package org.glorylight.hacks.social.model;

import java.io.Serializable;
import java.util.Date;
import java.util.UUID;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import org.hibernate.annotations.Type;

@Entity
@Table(name = "user_network")
@NamedQueries({
	@NamedQuery(name = "network-by-user", query = "from UserNetwork a where a.user.emailAddress = :userId"),
	@NamedQuery(name = "network-find-connection", query = "from UserNetwork a where a.user.emailAddress = :userId and a.connectTo = :connectTo"),
	@NamedQuery(name = "network-find-follower", query = "from UserNetwork a where a.connectTo = :userId"),
	@NamedQuery(name = "network-by-user-date", query = "from UserNetwork a where a.user.emailAddress = :userId " +
				"AND (a.dateCreated BETWEEN :startDate AND :endDate)"),
	@NamedQuery(name = "network-by-date", query = "from UserNetwork a where a.dateCreated BETWEEN :startDate AND :endDate")
	})
public class UserNetwork implements Serializable {
	
	private static final long serialVersionUID = -5126031493127464174L;

	@Id
	@Type(type = "uuid")
	@Column(length = 32)
	private UUID id;

	@ManyToOne
	@JoinColumn(name = "email_address")
	private User user;
	
	@Type(type = "uuid")
	@Column(name = "connect_to", nullable = false, length = 32)
	private UUID connectTo;
	
	@Temporal(TemporalType.DATE)
	@Column(name = "date_created")
	private Date dateCreated;

	public UserNetwork(User user, UUID connectTo, Date dateCreated) {
		new UserNetwork(UUID.randomUUID(), user, connectTo, dateCreated);
	}
	
	public UserNetwork(UUID userId, User user, UUID connectTo, Date dateCreated) {
		this.id = userId;
		this.user = user;
		this.connectTo = connectTo;
		this.dateCreated = dateCreated;
	}
	
	public UserNetwork(){
		this.id = UUID.randomUUID();
	}
	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	public UUID getConnectTo() {
		return connectTo;
	}

	public void setConnectTo(UUID connectTo) {
		this.connectTo = connectTo;
	}

	public UUID getId() {
		return id;
	}

	public Date getDateCreated() {
		return dateCreated;
	}

	public void setDateCreated(Date dateCreated) {
		this.dateCreated = dateCreated;
	}
	
	
}
